<div id="tb<?php echo $uniqid;?>" style="padding:5px">
    <table cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <td><a href="javascript:;" onclick="signupAdd();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-tianjia1"></i><span
                    class="l-btn-text">增加</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:;" onclick="signupEdit();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span
                    class="l-btn-text">编辑</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="signupDelete();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span
                    class="l-btn-text">删除</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:;" onclick="signupReload();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span
                    class="l-btn-text">重载</span></span></a></td>
            <td>&nbsp;&nbsp;<input id="signupKeywords" style="width:100px" type="text" class="easyui-input textbox">
            </td>
            <td><a href="javascript:void(0);" onclick="signupSearch();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span
                    class="l-btn-text">查询</span></span></a></td>
        </tr>
        </tbody>
    </table>
</div>
<div class="con"  style="-moz-user-select:none;">
    <table id="signup"></table>
</div>
<div id="signupDlg" class="easyui-dialog" style="width:720px; height:480px;" title="信息框" closed="true"></div>
<script>
    var signupAdd = function () {
        $("#signupDlg").dialog({
            title: '添加签约信息',
            closed: false,
            width: 720,
            height: 480,
            cache: false,
            href: '/admin/signup/add',
            modal: true,
            buttons: [{
                text: '保存',
                id: 'signupsubmit',
                iconCls: 'icon-ok',
            }, {
                text: '关闭',
                iconCls: 'icon-no',
                handler: function () {
                    $("#signupDlg").dialog('close');
                }
            }]
        });
    };
    var signupEdit = function (id) {
        let rowId = id || ($('#signup').datagrid('getSelected') && $('#signup').datagrid('getSelected').id);
        if (rowId) {
            $("#signupDlg").dialog({
                title: '编辑信息',
                closed: false,
                width: 720,
                height: 480,
                cache: false,
                href: '/admin/signup/edit?id=' + rowId,
                modal: true,
                buttons: [{
                    text: '保存',
                    id: 'signupsubmit',
                    iconCls: 'icon-ok',
                }, {
                    text: '关闭',
                    iconCls: 'icon-no',
                    handler: function () {
                        $("#signupDlg").dialog('close');
                    }
                }]
            });
        } else {
            $.messager.alert('提示', '请先选择要编辑的行！', 'warning');
        }
    };
    var signupDelete = function (id) {
        let rowId = id || ($('#signup').datagrid('getSelected') && $('#signup').datagrid('getSelected').id);
        if (rowId) {
            $.messager.confirm('提示', '确定删除吗？', function (r) {
                if (r) {
                    $.messager.progress();
                    $.post('/admin/signup/delete', {id: rowId}, function (data) {
                        $.messager.progress('close');
                        if (parseInt(data.ret) === 0) {
                            $.messager.show({
                                title: '提示',
                                msg: data.msg,
                                timeout: 3000,
                                showType: 'slide'
                            });
                            signupReload();
                        } else {
                            $.messager.alert('提示', data.msg, 'warning');
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.alert('提示', '请先选择要删除的记录！', 'warning');
        }
    };
    var signupReload = function () {
        $("#signup").datagrid('reload');
    };
    var signupSearch = function () {
        var height = $(window).height() - $(".top").height() - 46;
        var width = $(window).width() - $(".leftmenu").width() - 8;
        $("#signup").datagrid({
            title: '签约信息',
            width: width,
            height: height,//高度
            singleSelect: true,//如果为true，则只允许选择一行
            striped: true,//是否显示斑马线效果。
            rownumbers: true,//如果为true，则显示一个行号列。
            pagination: true,//是否显示分页
            pageSize: 15,
            pageList: [15, 20, 25, 50],
            method: 'post',
            sortName: 'id',
            sortOrder: 'desc',
            idField: 'id',
            url: '/admin/signup/index',
            queryParams: {keywords: $('#signupKeywords').val()},
            fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
            selectOnCheck: false,
            checkOnSelect: true,
            toolbar: '#tb<?php echo $uniqid;?>',
            columns: [[
                {field: 'member_id', title: '会员ID', width: fixWidth(5)},
                {field: 'realname', title: '名称', width: fixWidth(10)},
                {field: 'idcard_no', title: '身份证号', width: fixWidth(20)},
                {field: 'mobile', title: '签约手机号', width: fixWidth(10)},
                {field: 'signin_at', title: '签约时间', width: fixWidth(10)},
                {field: 'signout_at', title: '解约时间', width: fixWidth(10)},
                {
                    field: 'status', title: '签约状态', width: fixWidth(5), formatter: function (value, rowData, rowIndex) {
                        switch (value) {
                            case 0:
                                return '未签约';
                            case 1:
                                return '待审核';
                            case 2:
                                return '已签约'
                            case 4:
                                return '已解约';
                        }
                    }, styler(value, rowData, rowIndex){
                        switch (value) {
                            case 0:
                                return 'color: #666';
                            case 1:
                                return 'color: red';
                            case 2:
                                return 'color: green';
                            case 4:
                                return 'color: #999';
                        }
                    }
                },
                {
                    field: 'action', title: '操作', width: fixWidth(13), formatter: function (value, rowData, rowIndex) {
                        return '<a href="javascript:;" class="l-btn l-btn-small" onclick="signupEdit(' + rowData.id + ')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">编辑</span><span class="l-btn-icon icon-ok">&nbsp;</span></span></a>&nbsp;&nbsp;' +
                            '<a href="javascript:;" class="l-btn l-btn-small" onClick="signupDelete(' + rowData.id + ')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">删除</span><span class="l-btn-icon icon-no">&nbsp;</span></span></a>';
                    }
                },
            ]],
            onDblClickRow: function (index, field) {
                signupEdit();
            }
        });
    };
    signupSearch();
    onDatagridResize('#signup');
</script>
